package com.sv.controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.sv.dao.PageInfoDaoImpl;
import com.sv.model.SdContent;
import com.sv.model.SdContentChannel;
import com.sv.model.SdContentExt;
import com.sv.service.SdContentService;
import com.sv.web.ListSqlIdParam;
import com.sv.web.list.impl.ContentPageList;

@Controller
@RequestMapping(value = "/test")
public class TestController extends BaseController{

    @Autowired
    private SdContentService sdContentService;

    @RequestMapping(value = "/show", method = RequestMethod.GET)
    public String show(HttpServletRequest request, Model model) {
        try {
            
            SdContent content = sdContentService.selectSdContentById(1);

            SdContentChannel channel = sdContentService.selectSdContentChannel(content.getContentId());
            
            SdContentExt ext = sdContentService.selectContentExt(content.getContentId());
            
            model.addAttribute("content", content);
            model.addAttribute("channel", channel);
            model.addAttribute("ext", ext);
        }
        catch (SQLException e) {
            e.printStackTrace();
        }

        return "content";

    }

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(Model model,
            @RequestParam(required = false) String curPage,
            @RequestParam(required = false) String perPage) throws NumberFormatException, SQLException {

        model.addAttribute("title", "文章");
        
        model.addAttribute("startId", 2);
        
        model.addAttribute("endId", 8);
        
        model.addAttribute("channelId", 2);
        
        List list =  getPageListData(new ContentPageList(ListSqlIdParam.LIST), Integer.parseInt(curPage),Integer.parseInt(perPage), model);
        
        model.addAttribute("list",list);
        
        return "index";
    }
}
